<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="日期" prop="date">
        <el-date-picker v-model="queryParams.date" type="month" placeholder="请选择日期"
                        value-format="yyyy-MM" clearable/>
        <!--        <el-input v-model="queryParams.date" clearable/>-->
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="list" show-summary>
      <el-table-column label="日期" align="center" prop="days"/>
      <el-table-column label="注册人数" align="center" prop="regCount"/>
      <el-table-column label="充值次数" align="center" prop="sumCount"/>
      <el-table-column label="充值金额" align="center" prop="sumPrice"/>
      <el-table-column label="首充次数" align="center" prop="firstCount"/>
      <el-table-column label="首充金额" align="center" prop="firstPrice"/>
      <el-table-column label="当日注册并充值的总金额" align="center" prop="regDayPrice"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {queryStatistics} from "@/api/broker/broker";

export default {
  name: "statistics",
  data() {
    return {
      open: false,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 封禁IP和设备记录表格数据
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        date: undefined
      },
      date: undefined,
    };
  },
  created() {
    var date = new Date();
    var year = date.getFullYear();
    var month = this.formatNumber(date.getMonth() + 1);
    this.queryParams.date = year + '-' + month;
    this.getList();
  },
  methods: {
    formatNumber(num){
      return num < 10 ? '0' + num : num;
    },
    /** 查询封禁IP和设备记录列表 */
    getList() {
      this.loading = true;
      queryStatistics(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.date = this.queryParams.date;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
};
</script>
